<?php
declare (strict_types = 1);
namespace app\api\controller\season;

use app\LoginController;
use app\model\MyException;
use app\model\table\season\Rank;
use app\model\tablenot\tool\Tool;
use hg\apidoc\annotation as Apidoc;


/**
 * @Apidoc\Title("赛季-排行榜")
 */
class RankController extends LoginController
{
    /**
     * @Apidoc\Title("赛季-通用排行榜")
     * @Apidoc\Desc ("每一个类型返回的数据结构都不一样，请分开处理")
     * @Apidoc\Method("GET")
     * @Apidoc\Param ("type",require=true, type="int", desc="类型【1:赛季排行榜;2:本地排行榜;3:全部排行榜;4:工会排行榜;5:名人堂】")
     * @Apidoc\Returned("user_id", type="int", desc="用户id")
     * @Apidoc\Returned("user_name", type="int", desc="用户名称")
     * @Apidoc\Returned("score", type="int", desc="分数")
     * @Apidoc\Returned("union_id", type="int", desc="工会id")
     * @Apidoc\Returned("union_name", type="int", desc="工会名称")
     * @Apidoc\Returned("union_icon", type="int", desc="工会logo")
     * @Apidoc\Returned("rank", type="int", desc="排行")
     * @Apidoc\Returned("my", type="int", desc="我的排行榜")
     */
    public function commonAction()
    {
        try {
            Tool::checkParam(['type'], $this->get);
            $userObj = $this->user;
            $type = $this->get['type'];

            $RankModel = new Rank();
            $limit = 200;
            switch ($type){
                case 1:
                    $rs = $RankModel->getRanSaiji($userObj,$limit);
                    break;
                case 2:
                    $rs = $RankModel->getRanLocal($userObj,$limit);
                    break;
                case 3:
                    $rs = $RankModel->getRanAll($userObj,$limit);
                    break;
                case 4:
                    $rs = $RankModel->getRanUnion($limit);
                    break;
                case 5:
                    $rs = $RankModel->getMingrentang();
                    break;
                default:
                    throw new MyException("未知排行榜类型");
            }
            $this->setData($rs);
            $this->sendJson();
        } catch (MyException $e) {
            echo $e->toJson();
        }
    }
}
